home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / buffr2.zip / BDIMDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  6KB  |  178 lines

  1. Program Test_NDimensional_BufferedArrays;
  2.  
  3. Uses Crt,BD2Array,BD3Array,BD4Array;
  4.  
  5. Const
  6.   MaxBuff  = 0;   {Force Maximum available Buffer size}
  7.   MaxOne   = 24;
  8.   MaxTwo   = 25;
  9.   MaxThree = 26;
  10.   MaxFour  = 2;
  11.  
  12. Var
  13.   I,J,K,L : LongInt;
  14.   Value   : Integer;
  15.   RealVal : Real;
  16.   Space2  : BD2_IntArray;
  17.   Space3  : BD3_IntArray;
  18.   Space4  : BD4_IntArray;
  19.   Space5  : BD3_RealArray;
  20.  
  21. Begin
  22.   ClrScr;
  23.   WriteLn ('2 Dimensional BufferedArray (Integers) Test');
  24.   WriteLn ('Before Initialization Memory Available = ',MemAvail);
  25.   Space2.Init (MaxOne,MaxTwo,MaxBuff,'test.dat');
  26.   WriteLn ('After Initialization Memory Available = ',MemAvail);
  27.   WriteLn ('OverHead for 2D BufferedArray = ',SizeOf(Space2),' Bytes');
  28.   WriteLn;
  29.   WriteLn ('Allocated ',Space2.MaxSize,' Elements');
  30.   Value := 0;
  31.   For I := 0 to Space2.MaxIndex(1) do
  32.     For J := 0 to Space2.MaxIndex(2) do
  33.       Begin
  34.         Value := Value + 1;
  35.         GoToXY (1,10);
  36.         WriteLn ('Assigning Element ',I:4,J:4);
  37.         Space2.Accept (I,J,Value)
  38.       End;
  39.  
  40.   Space2.Store;
  41.   Space2.Load ('test.dat',MaxOne,MaxTwo,MaxBuff);
  42.  
  43.   For I := 0 to Space2.MaxIndex(1) do
  44.     For J := 0 to Space2.MaxIndex(2) do
  45.       Begin
  46.         GoToXY (1,12);
  47.         Write ('Retrieving Element ',I:4,J:4,'  Value is : ');
  48.         Space2.Retrieve (I,J,Value);
  49.         WriteLn (Value:7)
  50.       End;
  51.   WriteLn;
  52.   Write ('Press <Enter>/<Return> to Continue...');
  53.   ReadLn;
  54.   Space2.Destroy;
  55.  
  56.   ClrScr;
  57.   WriteLn ('3 Dimensional BufferedArray (Integers) Test');
  58.   WriteLn ('Before Initialization Memory Available = ',MemAvail);
  59.   Space3.Init (MaxOne,MaxTwo,MaxThree,MaxBuff,'test.dat');
  60.   WriteLn ('After Initialization Memory Available = ',MemAvail);
  61.   WriteLn ('OverHead for 3D BufferedArray = ',SizeOf(Space3),' Bytes');
  62.   WriteLn;
  63.   WriteLn ('Allocated ',Space3.MaxSize,' Elements');
  64.   Value := 0;
  65.   For I := 0 to Space3.MaxIndex(1) do
  66.     For J := 0 to Space3.MaxIndex(2) do
  67.       For K := 0 to Space3.MaxIndex(3) do
  68.         Begin
  69.           Value := Value + 1;
  70.           GoToXY (1,10);
  71.           WriteLn ('Assigning Element ',I:4,J:4,K:4);
  72.           Space3.Accept (I,J,K,Value)
  73.         End;
  74.  
  75.   Space3.Store;
  76.   Space3.Load ('test.dat',MaxOne,MaxTwo,MaxThree,MaxBuff);
  77.  
  78.   For I := 0 to Space3.MaxIndex(1) do
  79.     For J := 0 to Space3.MaxIndex(2) do
  80.       For K := 0 to Space3.MaxIndex(3) do
  81.         Begin
  82.           GoToXY (1,12);
  83.           Write ('Retrieving Element ',I:4,J:4,K:4,'  Value is : ');
  84.           Space3.Retrieve (I,J,K,Value);
  85.           WriteLn (Value:7)
  86.         End;
  87.   WriteLn;
  88.   Write ('Press <Enter>/<Return> to Continue...');
  89.   ReadLn;
  90.   Space3.Destroy;
  91.  
  92.   ClrScr;
  93.   WriteLn ('3 Dimensional BufferedArray (Reals) Test');
  94.   WriteLn ('Before Initialization Memory Available = ',MemAvail);
  95.   Space5.Init (MaxOne,MaxTwo,MaxThree,MaxBuff,'test.dat');
  96.   WriteLn ('After Initialization Memory Available = ',MemAvail);
  97.   WriteLn ('OverHead for 3D BufferedArray = ',SizeOf(Space5),' Bytes');
  98.   WriteLn;
  99.   WriteLn ('Allocated ',Space5.MaxSize,' Elements');
  100.   Value := 0;
  101.   For I := 0 to Space5.MaxIndex(1) do
  102.     For J := 0 to Space5.MaxIndex(2) do
  103.       For K := 0 to Space5.MaxIndex(3) do
  104.         Begin
  105.           Value := Value + 1;
  106.           GoToXY (1,10);
  107.           WriteLn ('Assigning Element ',I:4,J:4,K:4);
  108.           RealVal := Value;
  109.           Space5.Accept (I,J,K,RealVal)
  110.         End;
  111.  
  112.   Space5.Store;
  113.   Space5.Load ('test.dat',MaxOne,MaxTwo,MaxThree,MaxBuff);
  114.  
  115.   For I := 0 to Space5.MaxIndex(1) do
  116.     For J := 0 to Space5.MaxIndex(2) do
  117.       For K := 0 to Space5.MaxIndex(3) do
  118.         Begin
  119.           GoToXY (1,12);
  120.           Write ('Retrieving Element ',I:4,J:4,K:4,'  Value is : ');
  121.           Space5.Retrieve (I,J,K,RealVal);
  122.           WriteLn (RealVal:7:2)
  123.         End;
  124.   WriteLn;
  125.   Write ('Press <Enter>/<Return> to Continue...');
  126.   ReadLn;
  127.   Space5.Destroy;
  128.  
  129.   ClrScr;
  130.  
  131.   {NOTE: Due to the nature of the BufferedArray Object, greatest efficiency
  132.          is achieved by accessing in "reverse order" as is incorporated in
  133.          the 4-Dimensional example below.  This is increasingly true as the
  134.          total number of elements increases.  This access order minimizes
  135.          internal buffer flushing and reloading for "sequential" access, and
  136.          promises no benefit at all for random accessing of such arrays.}
  137.  
  138.   WriteLn ('4 Dimensional BufferedArray (Integers) Test');
  139.   WriteLn ('Before Initialization Memory Available = ',MemAvail);
  140.   Space4.Init (MaxOne,MaxTwo,MaxThree,MaxFour,MaxBuff,'test.dat');
  141.   WriteLn ('After Initialization Memory Available = ',MemAvail);
  142.   WriteLn ('OverHead for 4D BufferedArray = ',SizeOf(Space4),' Bytes');
  143.   WriteLn;
  144.   WriteLn ('Allocated ',Space4.MaxSize,' Elements');
  145.   WriteLn;
  146.   WriteLn ('"Reverse-Order" Accessing for greatest efficiency');
  147.   Value := 0;
  148.   Writeln (Space4.MaxIndex(4));
  149.   For I := 0 to Space4.MaxIndex(4) do
  150.     For J := 0 to Space4.MaxIndex(3) do
  151.       For K := 0 to Space4.MaxIndex(2) do
  152.         For L := 0 to Space4.MaxIndex(1) do
  153.           Begin
  154.             Value := Value + 1;
  155.             GoToXY (1,10);
  156.             WriteLn ('Assigning Element ',L:4,K:4,J:4,I:4);
  157.             Space4.Accept (L,K,J,I,Value)
  158.           End;
  159.  
  160.   Space4.Store;
  161.   Space4.Load ('test.dat',MaxOne,MaxTwo,MaxThree,MaxFour,MaxBuff);
  162.  
  163.   For I := 0 to Space4.MaxIndex(4) do
  164.     For J := 0 to Space4.MaxIndex(3) do
  165.       For K := 0 to Space4.MaxIndex(2) do
  166.         For L := 0 to Space4.MaxIndex(1) do
  167.           Begin
  168.             GoToXY (1,12);
  169.             Write ('Retrieving Element ',L:4,K:4,J:4,I:4,'  Value is : ');
  170.             Space4.Retrieve (L,K,J,I,Value);
  171.             WriteLn (Value:7)
  172.           End;
  173.   WriteLn;
  174.   Write ('Press <Enter>/<Return> to Continue...');
  175.   ReadLn;
  176.   Space4.Destroy
  177.  
  178. End.